package com.googlecode.imanager.jasper.util;

import java.util.Comparator;

import com.googlecode.imanager.jasper.print.RChild;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public abstract class RPrintComparator implements Comparator<RChild> {
    
    @Override
    public int compare(RChild a, RChild b) {
        return getStartPos(a) - getStartPos(b);
    }
    
    public int compareEndPos(RChild a, RChild b){
        return getEndPos(a) - getEndPos(b);
    }
    
    public int getEndPos(RChild a){
        return getStartPos(a) + getLength(a);
    }
    
    public int addStartPos(RChild a, int offset) {
        offset += getStartPos(a);
        setStartPos(a, offset);
        return offset; 
    }

    public int addLengthPos(RChild a, int offset) {
        offset += getLength(a);
        setLength(a, offset);
        return offset;
    }

    public abstract int getStartPos(RChild a);
    
    public abstract int getLength(RChild a);
    
    public abstract void setStartPos(RChild a, int value);
    
    public abstract void setLength(RChild a, int value);
    
    public abstract RPrintComparator getOpposition();
    
}